<template>
  <div class="main">
    <div class="header">
      <div class="nav">
        <div class="left">
          <div class="logo">机蜂小说网</div>
        </div>
        <div class="right">
          <router-link class="link" to="/"><span :class="{active:tabIndex === 1}" >首页</span></router-link>
          <router-link class="link" to="/category" ><span :class="{active:tabIndex === 2}">分类</span></router-link>
          <router-link class="link" to="/record" ><span :class="{active:tabIndex === 3}">记录</span></router-link>
          <router-link v-if="isLogin" class="link" to="/usercenter"><span :class="{active:tabIndex === 4}">我的</span></router-link>
          <a v-else class="link" href="javascript:;" @click="loginWin"><span>注册/登录</span></a>
        </div>
      </div>
    </div>
    <div class="content">
      <div v-if="heightFill" style="height: 60px"></div>
      <slot name="content"></slot>
    </div>
    <div class="footer">
      备案号:12312343453453<br>
      版权所有：机蜂网上书店
    </div>
    <login-form ref="loginForm" @loginSuccess="loginSuccess"/>
  </div>
</template>

<script>
import LoginForm from '@/components/LoginForm.vue'

export default {
  name: 'LayoutView',
  components: { LoginForm },
  props: {
    tabIndex: {
      type: Number,
      default: 1
    },
    heightFill: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      isLogin: false
    }
  },
  methods: {
    loginWin () {
      this.$refs.loginForm.init()
    },
    loginSuccess () {
      this.$http.get('api/vip/info').then(data => {
        if (data) {
          this.isLogin = true
        }
      }).catch(() => {})
    }
  },
  created () {
    this.loginSuccess()
  }
}
</script>

<style scoped lang="scss">
.main{
  min-height: 100vh;
  .header{
    height: 60px;
    width: 100%;
    background: rgba(0,0,0,.2);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 999;
    //border-bottom: 2px solid #42b983;
    .nav{
      height: 100%;
      width: 95%;
      margin: 0 auto;
      color: white;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .left{
        width: 200px;
        height: 100%;
        .logo{
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: end;
          background-image: url("@/assets/front-logo.png");
          background-repeat: no-repeat;
          background-size: 100px 60px;
          padding-right: 10px;
          font-weight: bold;
          font-size: 20px;
        }
      }
      .right{
        width: 320px;
        height: 100%;
        display: flex;
        .link{
          width: 80px;
          height: 100%;
          color: white;
          text-decoration: none;
          font-size: 14px;
          display: flex;
          align-items: center;
          &:hover{
            color: #42b983;
          }
          span{
            display: flex;
            align-items: center;
            justify-content: center;
            height: 60%;
            width: 90%;
            &.active{
              color: #42b983;
            }
          }
        }
      }
    }
  }
  .content{
    min-height: calc(100vh - 60px);
  }
  .footer{
    height: 59px;
    border-top: 1px solid #42b983;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
  }
}
</style>
